var app = getApp()
let api = require('../../../api/api.js')
var util = require("../../../utils/util.js")
Page({

  data: {
    navbar: [{
      name: "今日",
      index: "0"
    }, {
      name: "7日",
      index: "1"
    }, {
      name: "30日",
      index: "2"
    }],
    currentTab: 0,
    currentTab_1: 0,
    currentTabsIndex: 2,
    hide: true
  },
  H5: function() {
    var mobile = app.globalData.userInerInfo.number
    var id = app.globalData.userInerInfo.id
    wx.navigateTo({
      url: '/pages/H5/H5?mobile=' + mobile + "&id=" + id + "&status=2",
    })
  },
  navbar: function(e) {
    console.log(e)
    var index = e.currentTarget.dataset.index
    this.setData({
      currentTabsIndex: index
    })
  },

  // 无店铺时点击事件
  store: function() {
    wx.navigateTo({
      url: '../store/store',
    })
  },
  // 店铺管理
  channel: function() {
    var mobile = app.globalData.userInerInfo.number
    var id = app.globalData.userInerInfo.id
    wx.navigateTo({
      url: '../channel/channel?mobile=' + mobile + "&id=" + id + "&level=1",
    })
  },
  // 累积收益查看明细
  detail: function(e) {
    var mobile = app.globalData.userInerInfo.number
    var id = app.globalData.userInerInfo.id
    wx.navigateTo({
      url: '../detail/detail?mobile=' + mobile + "&id=" + id + "&level=1&index=0",
    })
  },

  onLoad: function(options) {
    console.log(options)
    const scene = decodeURIComponent(options.scene)
    // 页面初始化 options为页面跳转所带来的参数
    // console.log(app.globalData.userInerInfo)

  },
  onShow: function() {
    // console.log(app.globalData.userInerInfo)
    // console.log(app.globalData.userInerInfo.del_order)
    if (app.globalData.userInerInfo.hasOwnProperty("del_order")) {} else {
      app.globalData.userInerInfo.del_order = 0
    }
    this.setData({
      userInfo: app.globalData.userInerInfo
    })
  },
  //滑动切换
  swiperTab: function(e) {
    var that = this;
    if (this.current) {
      return false;
    } else {
      that.setData({
        currentTab_1: e.detail.current
      })
    }
  },
  guanli: function(e) {
    wx: wx.navigateTo({
      url: '../channel/channel',
    })
  },
  user: function(e) {
    var mobile = app.globalData.userInerInfo.number
    var id = app.globalData.userInerInfo.id
    var index = e.currentTarget.dataset.index
    console.log(index)
    wx.navigateTo({
      url: '../detail/detail?mobile=' + mobile + "&id=" + id + "&level=1&index=" + index,
    })
  },

  userMenu: function(e) {
    var mobile = app.globalData.userInerInfo.number
    var id = app.globalData.userInerInfo.id
    wx.navigateTo({
      url: '/pages/A/user_order/user_order?mobile=' + mobile + '&id=' + id + '&level=1&type=2'
    })
  },

  //点击切换
  clickTab: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  clickTab_1: function(e) {
    var that = this;
    if (this.data.currentTab_1 === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab_1: e.target.dataset.current
      })
    }
  },
  // 点击头像
  message: function(e) {
    console.log(e)
    var mobile = app.globalData.userInerInfo.number
    console.log(mobile)
    wx.navigateTo({
      url: '../message/message?mobile=' + mobile,
    })
  },
  onReachBottom: function(res) {
    console.log("页面触底了")
    var that = this
    var data = {
      mobile: app.globalData.userInerInfo.number,
      type: 1
    }
    if (that.data.hide) {
      wx.showLoading({
        title: "加载中"
      })
      api.pagebottom(data, res => {
        console.log(res)
        var dayManage = res.data.result.day_manage
        dayManage.day.forEach(function(element) {
          dayManage.daySum += element.detailed
        })
        dayManage.seven.forEach(function(element) {
          dayManage.sevenSum += element.detailed
        })
        dayManage.artmonth.forEach(function(element) {
          dayManage.artmonthSum += element.detailed
        })
        that.setData({
          hide: false,
          content: res.data.result.click,
          dayManage: dayManage
        })

        wx.hideLoading()
      })
    }
  },
  onPullDownRefresh() {
    var that = this
    var phone = util.getInfoFromStorage("mobile")
    var code = util.getInfoFromStorage("verify")
    util.sendRequest("/api/dblong/index", {
      mobile: phone,
      verify: code,
      type: 1
    }, "POST", false, function(res) {
      console.log(res)
      app.globalData.userInerInfo = res.result
      that.onShow()
      wx.stopPullDownRefresh()
    })
  },
})